<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/echarts.js"></script>
    <script src="./js/flexible.js"></script>
    <script src="./js/index.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #canvas {
            background-color: gray;
            margin: 50px auto 0;
            display: block;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="400" height="400"></canvas>
    <script>
        const ctx = document.getElementById("canvas")
        const gl = ctx.getContext("webgl")

        //着色器
        const VERTEX_SHADER_SOURCE = `
            attribute vec4 aPosition;
            attribute float aPointSize;
            void main() {
                gl_Position = aPosition;
                gl_PointSize = aPointSize;
            }
        `

        const FRAGMENT_SHADER_SOURCE = `
            void main() {
                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
            }
        `
        const program = initShader(gl, VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE)
        const aPosition = gl.getAttribLocation(program, "aPosition")
        const aPointSize = gl.getAttribLocation(program, "aPointSize")


        const points = new Float32Array([
            -0.5, -0.5, 10.0,
            0.5, -0.5, 20.0,
            0.0, 0.5, 30.0,
        ])

        const buffer = gl.createBuffer()
        gl.bindBuffer(gl.ARRAY_BUFFER, buffer)
        gl.bufferData(gl.ARRAY_BUFFER, points, gl.STATIC_DRAW)

        const BYTES = points.BYTES_PER_ELEMENT

        gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, BYTES * 3, 0)
        gl.enableVertexAttribArray(aPosition)

        gl.vertexAttribPointer(aPointSize, 1, gl.FLOAT, false, BYTES * 3, BYTES * 2)
        gl.enableVertexAttribArray(aPointSize)

        gl.drawArrays(gl.POINTS, 0, 3)

    </script>


    </script>

    </script>


</body>

</html>
